package com.qx.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data

@Table(name = "permission")
public class Permission {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private String permissionid;
	private String permissionvalue;
	private String permissionname;
	private String permissionmodule;
	private String permissionlastupdatetime;

	@JsonIgnore
	// 指定多对多关系，默认懒加载，只有调用getter方法时才加载数据
	@ManyToMany(fetch = FetchType.EAGER)
	@JoinTable(name = "rolepermission", // 指定第三张中间表名称
			joinColumns = { @JoinColumn(name = "permissionid") }, // 本表主键
			inverseJoinColumns = { @JoinColumn(name = "roleid") }) // 多对多关系另一张表
	// NotFound:意思是找不到引用的外键数据时忽略，NotFound默认是exception
	@NotFound(action = NotFoundAction.IGNORE)
	private List<Roles> list = new ArrayList<Roles>();

	
	public String test4() {
		return "Permission [permissionid=" + permissionid + ", permissionvalue=" + permissionvalue + ", permissionname="
				+ permissionname + ", permissionmodule=" + permissionmodule + ", permissionlastupdatetime="
				+ permissionlastupdatetime + ", list=" + list + "]";
	}

	

}
